package com.dhcc.controller;

import com.dhcc.service.IdGeneratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ID生成器控制器，提供生成ID的API。
 * @ProjectName Dhcc-Cloud
 * @PackageName com.dhcc.controller
 * @Title IdGeneratorController
 * @Date 2024/10/17 下午7:28
 * @Author LiuGuoting
 */
@RestController
@RequestMapping("/idGenerator")
public class IdGeneratorController {

    /**
     *  ID生成器服务
     */
    private final IdGeneratorService idGeneratorService;

    @Autowired
    public IdGeneratorController(IdGeneratorService idGeneratorService) {
        // 注入服务
        this.idGeneratorService = idGeneratorService;
    }

    /**
     * 生成唯一ID的API接口。
     *
     * @return 返回生成的唯一ID
     */
    @GetMapping("/nextId")
    public long generateId() {
        // 调用服务生成ID
        return idGeneratorService.nextId();
    }
}